package com.aididi.collection;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Auther: zx.xu
 * @Description:
 */
public class MapDemo {
    private static final int MAXIMUM_CAPACITY = 1 << 30;
    public static void main(String[] args) {
        synchronized (Object.class){

        }
        Map map1 = new HashMap(7);
        int cap = 1000;
        int n = cap - 1;
        n |= n >>> 1;
        n |= n >>> 2;
        n |= n >>> 4;
        n |= n >>> 8;
        n |= n >>> 16;
        int newCap = (n < 0) ? 1 : (n >= MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : n + 1;
        System.out.println(hash("xs"));
        map1.put(null,null);
        map1.put(1,2);
        map1.put(1,2);
        map1.put("name","张三");
        map1.remove(null);
        map1.put("age",15);
        String name = (String) map1.get("name");
        System.out.println(name);
        map1.hashCode();
        System.out.println(map1.entrySet());
        //四种遍历方式
        System.out.println(MAXIMUM_CAPACITY);
        int a = MAXIMUM_CAPACITY >>> 1;
        System.out.println(a);
        System.out.println(12>>>1);
        int num = 24/5;
        System.out.println(num);
        System.out.println(31^1);
        System.out.println((new Random().nextInt(10)+1)*1);
        System.out.println(9+(9>>1)); //jdk1.6以上 list扩容大小
        System.out.println(9*3/2+1);    //jdk1.6 list扩容大小
        System.out.println(Math.max(10,2));
        System.out.println(Integer.SIZE);
        System.out.println(Runtime.getRuntime().totalMemory());


        String str1 = "aa";
        System.out.println(str1.intern()==str1);


        Map map = new ConcurrentHashMap(17);
        map.put(1,2);
        map.put(56,12);
        map.get(1);
    }


    static final int hash(Object key) {
        int h;
        return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);
    }
}
